<?php

namespace App\Http\Controllers;

use App\Good;
use App\Models\Log;
use App\User;
use App\Users;
use Illuminate\Http\Request;

class Week extends Controller
{
    /**
     * 登录后入住日志表
     * @param Request $request
     * @return array
     */
    public function Login(Request $request)
    {
        //接收前台的值
        $name = $request['name'];
        $pwd = md5($request['pwd']);

        //判断用户名不能为空
        if($name!='')
        {
            if($pwd==$request['pwd'])
            {
                return ['code'=>2,'msg'=>'用户名或密码错误','res'=>null];
            }
        }else
        {
            return ['code'=>3,'msg'=>'用户名不能为空','res'=>null];
        }
        //实例化
        $model = new Users();
        $data = $model->dataLogin($name);


        if($data)
        {
//            $model = new Log();
//            $res = $model->LogData();
//            if($res)
//            {
//                return ['code'=>0,'msg'=>'日志入库成功','res'=>$res];
//            }else{
//                return ['code'=>1,'msg'=>'日志入库失败','res'=>null];
//            }
            return ['code'=>0,'msg'=>'登录成功','res'=>$data];
        }else{
            return ['code'=>1,'msg'=>'用户名或密码错误','res'=>null];
        }
    }

    /**
     * 展示
     * @return array
     */
    public function dataShow()
    {
        //实例化展示模型层
        $model = new Good();
        $res = $model->dataShow();
        if($res)
        {
            return ['code'=>0,'msg'=>'搜索成功','res'=>$res];
        }
    }
}
